import React, {useState} from 'react'
import { Button } from 'antd'
import './HooksDemo1.scss'
/**
 * @1 useState:React Hook的函数之一,目的是在函数组件中使用状态,以及修改状态,让组件更新
 * @2 let [state, setState] = useState(initialState)
 * @3 深刻理解上小文EC的概念,理解闭包,推算出 console.log(num)输出是多少
 */

const HooksDemo2 = function HooksDemo2() {
    const [num, setNum]=useState(0)
    const handle=()=>{
        setNum(100);
        setTimeout(() => {
            console.log(num);         
        }, 2000);
    }
    return <div className="demo">
        <span className="num">{num}</span>
        <Button type='primary' size='small' onClick={handle}>新增</Button>
    </div>
}

export default HooksDemo2